export default {
  data() {
    return { // 月季年周定期配置
    }
  },
  mounted() {

  },
  methods: {
    sessionSet(key, value) {
      // console.log(window.sessionStorage)
      let session = window.sessionStorage
      value = typeof value === 'object' ? JSON.stringify(value) : value
      session.setItem(key, value)
    },
    sessionGet(key) {
      let session = window.sessionStorage
      let value
      try {
        value = JSON.parse(session.getItem(key))
      } catch (error) {
        value = session.getItem(key)
      }
      return value
    },
    locationSet(key, value) {
      // console.log(window.sessionStorage)
      let localStorage = window.localStorage
      value = typeof value === 'object' ? JSON.stringify(value) : value
      localStorage.setItem(key, value)
    },
    locationGet(key) {
      let localStorage = window.localStorage
      let value
      try {
        value = JSON.parse(localStorage.getItem(key))
      } catch (error) {
        value = localStorage.getItem(key)
      }
      return value
    },
    sessionClean(key) {
      let session = window.sessionStorage
      session.removeItem(key);
    },
    _keepFoatMoney(money) {
      money = money.toString();
      //  console.log('log------------', index)
      if (money.indexOf(".") == -1) {
        return `${money}.00`;
      } else {
        let temp = money.split(".");
        if (temp[1].length < 2) {
          return `${temp[0]}.${temp[1]}0`;
        } else {
          return `${temp[0]}.${temp[1].substr(0, 2)}`;
        }
      }
    },
    /**
     * 补零
     * @param {*} data
     * @param {*} num
     */
    fillZero(data, num) {
      data = String(data);
      if (data.length >= num) {
        return data
      } else {
        let temp = data
        for (let i = 0; i < num - data.length; i++) {
          temp = 0 + temp
        }
        return temp
      }
    },
    /**
     * 跳转方法
     * @param path
     * @param query
     * @returns {*}
     * @author weizihua
     */
    routerPush(path, query, title) {
      // console.log(path, query, name);
      if (path == -1) {
        history.go(-1)
        return
      }
      // console.log('---进来了--',path, query, title)
      if (path) {
        this.$router.push({
          path: path,
          query: query,
          meta: {
            title: title
          },
        })
      }
    },
    getMenuList(isUpdateStore) {
      this.$http("/admin/getMenuList").then(res => {
        this.locationSet('routes', res.data)
        this.addRouters(res.data);
      });
    },
    parse(data,errValue){
      try {
        data = data.replace(/\r|\n|\\s/g,'')
        return JSON.parse(data);

      } catch (error) {
        // console.error('解析出错')
        return errValue
      }
    }
  }
}
